package cn.szzsi.model;

import cn.szzsi.model.base.BaseRoleResource;

import java.util.List;

//@TableBind(tableName = "role_resource", pkName = "roleSet_id")
public class PlatformRoleResource extends BaseRoleResource<PlatformRoleResource> {
	
	private static final long serialVersionUID = -372974665995862512L;
	
	public static final PlatformRoleResource dao = new PlatformRoleResource().dao();


	public List<PlatformRoleResource> getByRoleId(String roleId){
		return dao.find("select * from sys_platform_role_resource where roleId = ?",roleId);
	}

	public PlatformRoleResource getByRoleAndResourceId(String roleId, String resourceId){
		return dao.findFirst("select * from sys_platform_role_resource where roleId=? and resourceId = ?",roleId,resourceId);
	}

	public void deleteByRoleAndResourceId(String roleId, String resourceId){
		List<PlatformRoleResource> lbrr = dao.find("select * from sys_platform_role_resource where roleId=? and resourceId = ?",roleId,resourceId);
		if(lbrr!=null && lbrr.size()>0){
			for(PlatformRoleResource brr:lbrr){
				brr.delete();
			}
		}

	}

	//资源和权限是否对应在一起
	public boolean isRoleResourceRalationExsit(String rid, String roleId){
		List<PlatformRoleResource> lbrr = PlatformRoleResource.dao.find("select * from sys_platform_role_resource where roleId = ? and resourceId = ?",roleId,rid);
		if(lbrr!=null && lbrr.size()>0){
			return true;
		}else{
			return false;
		}
	}
	
	
	
	

}
